package com.xudow.app.dynamicstate_old.widget.exview;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.xudow.app.dynamicstate_old.data.ImageModel;
import com.xudow.app.dynamicstate_old.module.PictureActivity;

import java.util.ArrayList;
import java.util.Collection;

public class NetImageAdapter extends ArrayAdapter<String> implements View.OnClickListener {

    public NetImageAdapter(Context context) {
        super(context, 0);
    }

    public NetImageAdapter(Context context, String[] objects) {
        super(context, 0, objects);
    }

    public NetImageAdapter(Context context, Collection<String> objects) {
        super(context, 0, objects.toArray(new String[objects.size()]));
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        NetImagePieceView pieceView = new NetImagePieceView(getContext());
        pieceView.setImage(ImageModel.getMiddleImage(getItem(position)));
        pieceView.setTag(position);
        pieceView.setOnClickListener(this);
        pieceView.setOnClickListener(v -> {
            ArrayList<String> pictures = new ArrayList<String>();
            for (int i = 0; i < getCount(); i++) {
                pictures.add(getItem(i));
            }
            Intent i = new Intent(getContext(), PictureActivity.class);
            i.putExtra(PictureActivity.KEY_INDEX, position);
            i.putExtra(PictureActivity.KEY_PICTURES, pictures);
            getContext().startActivity(i);
        });
        return pieceView;
    }

    @Override
    public void onClick(View v) {
    }
}